//
//  DisplayUtil.m
//  AFNetworking
//
//  Created by 刘俊林 on 2021/10/8.
//

#import "DisplayUtil.h"

@implementation DisplayUtil

/// 获取状态栏高度
+(CGFloat) getStateBarHeight{
    if([UIApplication sharedApplication].isStatusBarHidden)
        return 0;
    
    if (@available(iOS 13.0, *)) {
        NSSet *set = [UIApplication sharedApplication].connectedScenes;
        UIWindowScene *windowScene = [set anyObject];
        UIWindow *window = windowScene.windows.firstObject;
        return window.safeAreaInsets.top;
    } else if (@available(iOS 11.0, *)) {
        UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
        return window.safeAreaInsets.top;
    }
    return 0;
}

/// 获取导航栏高度
+(CGFloat) getNavigationBarHeight{
    return 44.0f;
}

/// 状态栏+导航栏高度
+(CGFloat) getNavigationBarAndStateHeight{
    return [DisplayUtil getStateBarHeight] + [DisplayUtil getNavigationBarHeight];
}

/// 顶部安全距离(无导航栏)
+(CGFloat)safeDistanceTop{
    return [self getStateBarHeight];
}

/// 获取底部安全距离
+(CGFloat) getBottomSafeHeight{
    // 非全面屏无底部安全区
    if([[UIScreen mainScreen]bounds].size.height <= 736)
        return 0;
    
    if (@available(iOS 13.0, *)) {
        NSSet *set = [UIApplication sharedApplication].connectedScenes;
        UIWindowScene *windowScene = [set anyObject];
        UIWindow *window = windowScene.windows.firstObject;
        return window.safeAreaInsets.bottom;
    } else if (@available(iOS 11.0, *)) {
        UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
        return window.safeAreaInsets.bottom;
    }
    return 0;
}

/// 获取屏幕宽度
+(CGFloat) getScreenWidth{
    return [[UIScreen mainScreen]bounds].size.width;
}

/// 获取屏幕高度
+(CGFloat) getScreenHeight{
    return [[UIScreen mainScreen]bounds].size.height;
}

/// 是否是刘海屏
+(bool) isIphoneX{
    CGFloat height = [self getScreenHeight];
    // 736为iphone8 plus高度
    return  (height > 736.f);
}

/// 获取底部tabbar高度
+(CGFloat) getTabbarHeight{
    return 49.0f;
}

/// 获取底部安全距离+tabbar高度
+(CGFloat) getBottomsafeAndTabbarHeight{
    return [DisplayUtil getTabbarHeight] + [DisplayUtil getBottomSafeHeight];
}

@end
